home *** CD-ROM | disk | FTP | other *** search
- #include <libraries/commodities.h>
- #include <proto/SysInfo.h>
- #include <libraries/SysInfo.h>
- #include <libraries/ScreenNotify.h>
- #include <exec/memory.h>
- #include <dos/dos.h>
- #include <intuition/intuition.h>
- #include <intuition/classusr.h>
- #include <intuition/gadgetclass.h>
- #include <intuition/cghooks.h>
- #include <intuition/icclass.h>
- #include <intuition/classes.h>
- #include <utility/tagitem.h>
- #include "gaugeclass.h"
- #include "launchclass.h"
- #include "tinymeter.h"
- /* defaultshit */
- #define Version "4.22"
-
- #ifndef MAKE_ID
- #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
- #endif
-
- const char *version="$VER: TinyMeter V" Version;
-
- struct Library *RetinaBase;
- struct Library *ShutdownBase;
- struct Library *TimerBase;
- struct Library *SysInfoBase;
- struct Library *ScreenNotifyBase;
- struct Library *CxBase;
- struct Library *DataTypesBase;
- struct Library *LocaleBase;
-
- extern struct WBStartup *_WBBenchMsg;
-
- show(int what)
- {
- static struct EasyStruct easymsg =
- {
- sizeof(struct EasyStruct),
- 0,
- "TinyMeter " Version " information",
- 0L,
- "OK"
- };
- static char *err_msg[]=
- {
- "Not enough memory.",
- "Could not open the window.",
- "Port initialization failed",
- "BOOPSI allocation failed",
- "timer.device error!",
- "Startup problem!",
- "Preferences error. Using defaults!",
- "Could not open listfile"
- };
-
- easymsg.es_TextFormat=err_msg[what];
- EasyRequest(NULL, &easymsg, NULL);
- }
-
- int getNum(struct tm_gau_set *list)
- {
- int num=1;
- while(list=list->next)num++;
- return(num);
- }
-
- useDefault(struct tm_sys_set *set,struct tm_data *data)
- {
- struct tm_gau_set *many,
- *act,
- *old;
-
- static struct tm_sys_set default_set=
- {
- "TM40",
- 1,
-
- 10,
- 10,
- 450,
- 2,
-
- "Workbench",
-
- "",
- 8,
-
- bg_none,
- "",
- FALSE,
- -3,
- FALSE,0x55555555,0x55555555,0x55555555,
-
- 5,
- 1,
-
- 0,
- TRUE,
-
- win_normal,
- 0,
- 4,
- 4,
- 8,
- 8,
-
- bd_standard,
- FALSE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
- FALSE,0x0,0x0,0x0,
-
- idle_own
- };
-
- static struct tm_gau_set g3=
- {
- typ_idle,
- typ_histmeter,
-
- 200,
-
- "",
- 8,
-
- "ChipMem",
- "CPU %p%% free",
- "",
- ind_right,
- TRUE,
- TRUE,
- TRUE,
- TRUE,
- FALSE,
- FALSE,
- TRUE,
-
- TRUE,2,0,0,
- TRUE,2,0,0,
- FALSE,0,0xFFFFFFFF,0,
- FALSE,0,0,0xFFFFFFFF,
- FALSE,0xFFFFFFFF,0,0,
- TRUE,2,0,0,
- TRUE,1,0,0,
- TRUE,1,0,0,
-
- NULL
- };
-
- static struct tm_gau_set g2=
- {
- typ_fast,
- typ_gauge,
-
- 20,
-
- "",
- 8,
-
- "FastMem",
- "%td Bytes free",
- "",
- ind_right,
- TRUE,
- TRUE,
- TRUE,
- TRUE,
- FALSE,
- FALSE,
- FALSE,
-
- TRUE,2,0,0,
- TRUE,2,0,0,
- FALSE,0,0xFFFFFFFF,0,
- FALSE,0,0,0xFFFFFFFF,
- FALSE,0xFFFFFFFF,0,0,
- TRUE,2,0,0,
- TRUE,1,0,0,
- TRUE,0,0,0,
-
- &g3
- };
-
-
- static struct tm_gau_set g1=
- {
- typ_chip,
- typ_gauge,
-
- 20,
-
- "topaz.font",
- 8,
-
- "ChipMem",
- "%td Bytes free",
- "",
- ind_right,
- TRUE,
- TRUE,
- TRUE,
- TRUE,
- FALSE,
- FALSE,
- FALSE,
-
- TRUE,2,0,0,
- TRUE,2,0,0,
- FALSE,0,0xFFFFFFFF,0,
- FALSE,0,0,0xFFFFFFFF,
- FALSE,0xFFFFFFFF,0,0,
- TRUE,2,0,0,
- TRUE,1,0,0,
- TRUE,0,0,0,
-
- &g2
- };
-
- CopyMem((char *)&default_set,set,sizeof(struct tm_sys_set));
-
- if(act=(struct tm_gau_set *)AllocVec(sizeof(struct tm_gau_set),0L))
- {
- many=&g1; data->list=act; CopyMem((char *)many,act,sizeof(struct tm_gau_set));
- while(many=many->next)
- {
- old=act;
- if(act=(struct tm_gau_set *)AllocVec(sizeof(struct tm_gau_set),0L))
- {
- old->next=act;
- CopyMem((char *)many,act,sizeof(struct tm_gau_set));
- }
- else {act->next=0L;return;}
- }
- act->next=0L;
- }
- else data->list=0L;
- }
-
- int main(void)
- {
-
- struct tm_sys_set *set;
- struct tm_data *data;
-
- Class *gclass,*lclass;
- ULONG cxsigflag;
- CxMsg *msg;
- CxObj *broker;
- struct MsgPort *broker_mp;
-
- static struct NewBroker newbroker =
- {
- NB_VERSION,
- "TinyMeter V" Version,
- "TinyMeter V" Version " © by Tinic Urou",
- "Shows system states",
- NBU_UNIQUE,
- 0,
- -3,
- 0,
- 0
- };
-
- if(LocaleBase=(struct Library *)OpenLibrary("locale.library",0L))
- {
- if(DataTypesBase=(struct Library *)OpenLibrary("datatypes.library",0L))
- {
- if(CxBase=(struct Library *)OpenLibrary("commodities.library",0L))
- {
- if(data=(struct tm_data *)AllocVec(sizeof(struct tm_data),MEMF_CLEAR))
- {
- if(set=(struct tm_sys_set *)AllocVec(sizeof(struct tm_sys_set)+8L,0L))
- {
- if((gclass=(Class *)initGaugeGadgetClass())&&(lclass=(Class *)initLauncherGadgetClass()))
- {
- char *my_file;
- struct tm_gau_set *many,*act;
- if(my_file=(UBYTE *)Open("ENV:TinyMeter",MODE_OLDFILE))
- {
- if(!Read(my_file,set,(ULONG)sizeof(struct tm_sys_set)))
- {
- show(err_nopre);
- useDefault(set,data);
- }
- else
- {
- if((ULONG)*((ULONG *)&set->set_header[0])==0x544D3430)
- {
- if(act=(struct tm_gau_set *)AllocVec(sizeof(struct tm_gau_set),0L))
- {
- data->list=act; many=act;
- while(Read((char *)my_file,(char *)act,(ULONG)sizeof(struct tm_gau_set))&&act)
- {
- many=act;
- if(act=(struct tm_gau_set *)AllocVec(sizeof(struct tm_gau_set),0L)) many->next=act;
- else DisplayBeep(0);
- }
- many->next=NULL; FreeVec(act); act=NULL;
- }
- else DisplayBeep(0);
- }
- else
- {
- show(err_nopre);
- useDefault(set,data);
- }
- }
- Close(my_file);
- }
- else
- {
- show(err_nopre);
- useDefault(set,data);
- }
-
- data->num_of_gaug=getNum(data->list);
-
- Forbid();
- SetTaskPri(FindTask(0L),set->pri);
- Permit();
-
- Delay(set->start_wait*50L);
-
- if(broker_mp = (struct MsgPort *)CreatePort(0,0))
- {
- newbroker.nb_Port = (struct MsgPort *)broker_mp;
-
- if (broker = (CxObj *)CxBroker(&newbroker, NULL))
- {
- cxsigflag = 1L << broker_mp->mp_SigBit;
- ActivateCxObj(broker, 1L);
-
- RetinaBase=(struct Library *)OpenLibrary("retina.library",0L);
-
- switch (set->Executive)
- {
- case idle_none:
- data->executive=idle_none;
- break;
- case idle_executive:
- if(SysInfoBase = (struct Library *)OpenLibrary(SYSINFONAME, SYSINFOVERSION))
- {
- if(data->si =(struct SysInfo *)InitSysInfo())
- data->executive=idle_executive;
- else
- data->executive=idle_none;
- }
- else data->executive=idle_none;
- break;
- case idle_own:
- init_idle();
- data->executive=idle_own;
- break;
- }
-
- data->scrnot=FALSE; if(set->start_usescreennotify)
- if(ScreenNotifyBase=(struct Library *)OpenLibrary("screennotify.library",SCREENNOTIFY_VERSION))
- data->scrnot=TRUE;
-
- if(InitWorkbenchPath(data))
- {
- if(openWindow(set,data))
- {
- drawBackground(set,data);
- allocGadgets(set,data,gclass,lclass);
- set=(struct tm_sys_set *)handler(set,data,broker_mp,broker,cxsigflag,gclass,lclass);
- closeWindow(set,data);
- removeGadgets(set,data);
- }
- else show(err_nowin);
- FreeWorkbenchPath(data);
- }
- else show(err_nosta);
-
- switch (data->executive)
- {
- case idle_executive:
- FreeSysInfo(data->si);
- CloseLibrary(SysInfoBase);
- break;
-
- case idle_own:
- free_idle();
- break;
-
- }
- if(data->scrnot)CloseLibrary(ScreenNotifyBase);
- if(RetinaBase) CloseLibrary(RetinaBase);
- while(msg = (CxMsg *)GetMsg(broker_mp)) ReplyMsg((struct Message *)msg);
- DeleteCxObj(broker);
- }
- else show(err_nosta);
- DeletePort(broker_mp);
- }
- else show(err_nosta);
- if(many=data->list)
- {
- do
- {
- act=many->next;
- FreeVec(many);
- }
- while(many=act);
- }
- freeGaugeGadgetClass(gclass);
- freeLauncherGadgetClass(lclass);
- }
- else show(err_noboo);
- FreeVec(set);
- }
- else show(err_nomem);
- FreeVec(data);
- }
- else show(err_nomem);
- CloseLibrary(CxBase);
- }
- CloseLibrary(DataTypesBase);
- }
- CloseLibrary(LocaleBase);
- }
- }
-
- int wbmain(void)
- {
- return(main());
- }
-
-
-